package com.atxiaodei.单向链表;

/**
 * @ClassName LinkList
 * @Deacription TODO
 * @Author 王盟
 * @Date 2021/6/3 10:39
 * @Version 1.0
 **/
public class LinkList {
    private Link first;

    public LinkList() {
        this.first = null;
    }

    public boolean isEmpty() {
        return (this.first == null);
    }

    public void insertFirst(int id, double dd) {
        Link newLink = new Link(id, dd);
        newLink.next = first;//newLink --> old first
        this.first = newLink;//first --> newLink
    }

    public Link deleteFirst() {
        Link temp = this.first;
        this.first = this.first.next;
        return temp;
    }

    public void displayList() {
        System.out.println("List (first --> last)");
        Link current = first;

        while (current != null) {
            current.displayLink();
            current = current.next;
        }
        System.out.println(" ");
    }

}